package com.waymap.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.waymap.domain.TransactionItemInventoryDetails;
import com.waymap.domain.TransactionItems;
import com.waymap.domain.Transactions;
import com.waymap.mapper.TransactionItemInventoryDetailsMapper;
import com.waymap.mapper.TransactionItemsMapper;
import com.waymap.mapper.TransactionsMapper;
import com.waymap.service.SyncService;

@Service
public class SyncServiceImpl implements SyncService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private TransactionsMapper transactionsMapper;
    @Resource
    private TransactionItemsMapper transactionItemsMapper;
    @Resource
    private TransactionItemInventoryDetailsMapper transactionItemInventoryDetailsMapper;

    /**
     * 获取transactions单条数据
     * @param param
     * @return
     */
    @Override
    public Map<String, Object> getTransactionInfo(String tranid,String accountId) {

    	Transactions tmp = new Transactions();
    	tmp.setAccountId(accountId);
    	tmp.setTranid(tranid);
    	List<Transactions> tr = transactionsMapper.select(tmp);
    	Transactions trVo = tr.get(0);
    	
    	TransactionItems transactionItem = new TransactionItems();
        transactionItem.setAccountId(accountId);
        transactionItem.setTransactionId(tranid);
        List<TransactionItems> tris = transactionItemsMapper.select(transactionItem);
        List<TransactionItemInventoryDetails> tiids = new ArrayList<TransactionItemInventoryDetails>();
    	for(TransactionItems tmp1:tris) {
    		TransactionItemInventoryDetails transactionItemInventoryDetails =  new TransactionItemInventoryDetails();
    		transactionItemInventoryDetails.setAccountId(accountId);
    		transactionItemInventoryDetails.setTransactionId(tranid);
    		transactionItemInventoryDetails.setItemId(tmp1.getItemId());
    		List<TransactionItemInventoryDetails> tids = transactionItemInventoryDetailsMapper.select(transactionItemInventoryDetails);
    		tiids.addAll(tids);
    	}
    	Map result = new HashMap();
    	result.put("Transactions", trVo);
    	result.put("TransactionItems", tris);
    	result.put("TransactionItemInventoryDetails", tiids);
        return result;
    }




}
